namespace ghost
{
    /**胜利界面*/
    export class CallUI extends GameUIBase{
        public item0:CallItem;
        public item1:CallItem;
        public item2:CallItem;
        private _curItem:CallItem;
        public callBtn:GYSprite;
        constructor(){
            super();
            let s= this;
            s.width = GameManager.DESIGN_WIDTH;
            s.height = GameManager.DESIGN_HEIGHT;

            let i:number,len:number;
            let item:CallItem;
            let data = [2,1,0];
            len = 3;
            for(i=0;i<len;++i)
            {                
                s["item" + i] = item = new CallItem(Number(data[i]), Main.instance.getRes(Conf.monster + `tower${data[i]}/idle/0.png`));
                item.on(Laya.Event.CLICK, s, s.selectItem);
                s.addChild(item);
            }
            s.callBtn = new GYSprite;
            s.callBtn.texture = Main.instance.getRes(Conf.scene + "commonBtn.png");
            s.addChild(s.callBtn);

            let btnIcon = new GYSprite;
            btnIcon.texture = Main.instance.getRes(Conf.scene + "gold.png");
            btnIcon.x = 80;
            btnIcon.y = 19;
            s.callBtn.addChild(btnIcon);
            let btnLab = new Laya.Text;
            btnLab.stroke = 6;
            btnLab.strokeColor = "#682323"
            btnLab.fontSize = 30;
            btnLab.color = "#f3ff8f";
            btnLab.text = "30";
            btnLab.x = 120;
            btnLab.y = 27;
            s.callBtn.addChild(btnLab);
            s.callBtn.on(Laya.Event.CLICK, s, s.call);
            s.maskClkEnabled = false;
        }      
        private selectItem(e:Laya.Event):void
        {
            let s= this;
            let item:CallItem = <CallItem>e.currentTarget;
            if(s._curItem)
                s._curItem.setSelect(false);
            item.setSelect(true);
            s._curItem = item;            
            if(GuideTip.instance.step == 4)
                GuideTip.instance.nextGuide();
            if(GuideTip.instance.step == 5)
                GuideTip.instance.addGuide(s.callBtn);
        }
        private call(e:Laya.Event):void
        {
            let s = this;
            let logic:CommonScene = <CommonScene>Module.getInstance().sceneMgr.sceneLogic;
            if(s._curItem)
            {
                logic.levelUpTower(s._curItem.index);
                s.hide();
            }
            else
                TextTip.show("请选择需要升级的防御塔");
        }
        public resize():void
        {
            let s = this;
            super.resize();
            s.item1.x = s.width - s.item1.width >> 1;
            s.item0.x = s.item1.x - s.item0.width - 10;
            s.item2.x = s.item1.x + s.item1.width + 10;
            s.item0.y = 400;
            s.item1.y = s.item2.y = s.item0.y;
            s.callBtn.y = s.item1.y + s.item1.height + 105;
            s.callBtn.x = s.width - s.callBtn.width >> 1;
        }    
        public show(pr:Laya.Sprite=null, mask:boolean=true, tween:boolean=true):void
        {
            super.show(pr, mask, tween);
            let s = this;
            SceneManager.instance.pause();
            if(GuideTip.instance.step == 4)
                GuideTip.instance.addGuide(s.item1);
            let len:number;
            len = 3;
            let item:CallItem;
            while(--len>-1)
            {
                item = s["item" + len];
                item.reset();
            }
        }    
        public hide(): void {
            super.hide();
            SceneManager.instance.resume();
        }
    }
}